
const express = require("express");
const router = express.Router();
const {asynchandler} = require("../router/getResult")
const sevBook = require("../sever/serveBook");
const sevRead = require("../sever/serveReadTable");
//查找书籍
router.get("/findBook",asynchandler(async (req,res)=>{
  const result = await sevBook.findBooks(req.query);

  return result;
}))

//详情页获取单个书籍的详细信息
router.get("/idFindBook",asynchandler(async (req,res)=>{
    const result = await sevBook.findBook(req.query.id);

    return result;
}))
//发送过来的数据得有个book对象或者book数组，数组是批量添加书籍
router.put("/addBook",asynchandler(async(req,res)=>{
    const result = await sevBook.addBook(req.query.book);
    return result;
} ))

router.get("/getBookType",asynchandler(async(req,res)=>{

  const type =await sevBook.getBookType();
  let result = type.map((item)=>{
    return item.type

  })
  return result;
}))
//对书籍进行查询，模糊
router.get("/search",asynchandler(async (req,res)=>{
      let result = await sevBook.findBookLike(req.query.search);
      
      return result;
}))
//获取用户读书排行
router.get('/getUserTop' ,asynchandler( async(req,res)=>{
  const result = await sevRead.findUserReadTop();
  return result;
}))
//获取热门书籍
router.get('/getBookTop' ,asynchandler( async(req,res)=>{
  const result = await sevRead.findTopBook();
  return result;
}))
//获取用户书单，根据传过来的Boolean值来判定是已还书单还是在借书单


module.exports = router;